home *** CD-ROM | disk | FTP | other *** search
- ###############################################################################
- # $Id: memory.tk,v 1.6 1995/02/18 18:00:59 bmott Exp $
- ###############################################################################
- # memory.tk - Routines to handle the memory viewing screen
- #
- # Copyright 1993
- # Bradford W. Mott
- # November 11,1993
- ###############################################################################
- # $Log: memory.tk,v $
- # Revision 1.6 1995/02/18 18:00:59 bmott
- # Added routine to catch bad filenames in the dump utility
- #
- # Revision 1.5 1995/02/11 03:29:30 bmott
- # Fixed bug in dump memory to file utility
- #
- # Revision 1.4 1995/01/01 03:01:13 bmott
- # Added bitmaps to buttons, changed method to alter memory locations,
- # and added a dismiss button
- #
- # Revision 1.3 1994/09/13 23:29:01 bmott
- # Changed the file selector calls to use BtkFileSelector
- #
- # Revision 1.2 1994/08/22 08:25:03 bmott
- # Changed the dump dialog to popup in the memory viewer window
- #
- # Revision 1.1 1994/02/18 20:29:40 bmott
- # Initial revision
- #
- ###############################################################################
-
-
- ###############################################################################
- # Check to make sure the the address is within range
- ###############################################################################
- proc CheckMemoryViewerAddress {} {
- global MemoryViewer
-
- if {[expr $MemoryViewer(Address) + $MemoryViewer(WPS) - 1] > \
- $MemoryViewer(MaximumAddress)} {
- set MemoryViewer(Address) [expr $MemoryViewer(MaximumAddress) - \
- $MemoryViewer(WPS) + 1]
- }
- if {$MemoryViewer(Address) < "0"} {
- set MemoryViewer(Address) 0
- }
- }
-
- ###############################################################################
- # Refresh the memory viewer text window
- ###############################################################################
- proc RefreshMemoryViewer {} {
- global MemoryViewer
-
- ## Make sure the memory viewer exists
- if {[winfo exists .memoryViewer]==0} {return}
-
- ## Get the length, address, and words per line in hexidecimal form
- set length [format "%x" $MemoryViewer(WPS)]
- set address [format "%x" $MemoryViewer(Address)]
- set wpl [format "%x" $MemoryViewer(WPL)]
-
- ## Ask the simulator for the memory dump
- PutLine "ListMemory $MemoryViewer(AddressSpace) $address $length $wpl"
-
- ## Empty the text widget
- .memoryViewer.text delete 1.0 end
-
- ## Put the memory dump in the text widget
- set address [expr $MemoryViewer(Address)]
- foreach i [GetList] {
- set line "[format %0$MemoryViewer(AddressLength)x $address]: $i\n"
- .memoryViewer.text insert end "$line"
- set address [expr $address+$MemoryViewer(WPL)]
- }
- }
-
- ###############################################################################
- # Change the address the viewer is displaying
- ###############################################################################
- proc ChangeMemoryViewerAddress {} {
- global MemoryViewer
-
- ## Get the value from the user
- set value [ChildEntryDialog .memoryViewer "Enter new address:"\
- {^[0-9a-fA-F]+$}]
-
- ## If Okay was press then change the address
- if {$value!=""} {
- scan $value "%x" MemoryViewer(Address)
- CheckMemoryViewerAddress
- RefreshMemoryViewer
- }
- }
-
- ###############################################################################
- # Alter the memory location where the mouse button was pressed
- ###############################################################################
- proc MemoryViewerAlterMemory {x y} {
- global MemoryViewer
-
- if {[.memoryViewer.text get "@$x,$y wordstart" "@$x,$y wordend"] == " "} {
- return
- }
- scan [.memoryViewer.text index "@$x,$y wordend"] "%d.%d" endl endw
- if {$endw > [expr $MemoryViewer(AddressLength)+1]} {
- .memoryViewer.text tag add WordSelectTag "@$x,$y wordstart" "@$x,$y wordend"
- }
-
- ## Get a list of indices of all of the selected words
- set range [.memoryViewer.text tag ranges WordSelectTag]
-
- ## If no word is selected then leave
- if {$range==""} { return }
-
- ## Build a regular expression to check the entry against
- set reg_exp ""
- for {set t 0} {$t < $MemoryViewer(WordLength)} {set t [expr $t+1]} {
- for {set s 0;set add ""} {$s < [expr $t+1]} {set s [expr $s+1]} {
- set add "$add\[0-9a-fA-F\]"
- }
- if {$reg_exp==""} {
- set reg_exp "(^$add\$)"
- } else {
- set reg_exp "$reg_exp|(^$add\$)"
- }
- }
-
- ## Get the value from the user
- set value [ChildEntryDialog .memoryViewer \
- "Enter new value for the selected memory location(s):" \
- $reg_exp]
-
- ## If Okay was pressed then we have to set each word to the new value
- if {$value!=""} {
- for {set t 0} {$t<[llength $range]} {set t [expr $t+2]} {
- scan "[lindex $range $t]" "%d.%d" y x
- set address [expr $MemoryViewer(Address)+($y-1)*$MemoryViewer(WPL)+\
- ($x-$MemoryViewer(AddressLength)-1)/\
- (1+$MemoryViewer(WordLength))]
- set address [format "%x" $address]
- PutLine "SetMemory $MemoryViewer(AddressSpace) $address $value"
- set dummy [GetList]
- }
- }
- RefreshMemoryViewer
- }
-
- ###############################################################################
- # Dump memory to a file
- ###############################################################################
- proc DumpMemoryViewer {} {
- global MemoryViewer
- global ReturnValue
-
- ## Just in case destroy the window
- catch {destroy .memoryViewer.dumpDialog}
-
- frame .memoryViewer.dumpDialog -relief raised -borderwidth 3
-
- frame .memoryViewer.dumpDialog.start -relief groove -borderwidth 2
- label .memoryViewer.dumpDialog.start.label -text "Starting Address:"
- entry .memoryViewer.dumpDialog.start.entry -width 10 -relief sunken
- bind .memoryViewer.dumpDialog.start.entry <Return> {
- focus .memoryViewer.dumpDialog.end.entry
- }
- pack .memoryViewer.dumpDialog.start.label -side left -padx 4
- pack .memoryViewer.dumpDialog.start.entry -side left \
- -fill x -expand 1 -padx 4
-
- frame .memoryViewer.dumpDialog.end -relief groove -borderwidth 2
- label .memoryViewer.dumpDialog.end.label -text "Ending Address:"
- entry .memoryViewer.dumpDialog.end.entry -width 10 -relief sunken
- bind .memoryViewer.dumpDialog.end.entry <Return> {
- set ReturnValue "[.memoryViewer.dumpDialog.start.entry get] [.memoryViewer.dumpDialog.end.entry get]";
- destroy .memoryViewer.dumpDialog
- }
- pack .memoryViewer.dumpDialog.end.label -side left -padx 4
- pack .memoryViewer.dumpDialog.end.entry -side left \
- -fill x -expand 1 -padx 4
-
- frame .memoryViewer.dumpDialog.buttons
- button .memoryViewer.dumpDialog.buttons.ok -text "Okay" \
- -command {set ReturnValue "[.memoryViewer.dumpDialog.start.entry get] [.memoryViewer.dumpDialog.end.entry get]"; \
- destroy .memoryViewer.dumpDialog }
- button .memoryViewer.dumpDialog.buttons.cancel -text "Cancel" \
- -command {set ReturnValue ""; destroy .memoryViewer.dumpDialog}
- pack .memoryViewer.dumpDialog.buttons.ok -side left -expand 1 -fill x -padx 4
- pack .memoryViewer.dumpDialog.buttons.cancel -side right -expand 1\
- -fill x -padx 4
-
- pack .memoryViewer.dumpDialog.start -side top -fill x -pady 4 -padx 4
- pack .memoryViewer.dumpDialog.end -side top -fill x -pady 4 -padx 4
- pack .memoryViewer.dumpDialog.buttons -side top -fill x -pady 4
-
- ## Place the dump dialog
- place .memoryViewer.dumpDialog -relx 0.5 -rely 0.5 -anchor center
-
- ## Make this a modal dialog
- tkwait visibility .memoryViewer.dumpDialog
- focus .memoryViewer.dumpDialog.start.entry
- grab set .memoryViewer.dumpDialog
- tkwait window .memoryViewer.dumpDialog
-
- # If Okay was pressed set the register value in the simulator
- if {$ReturnValue!=""} {
- if {[regexp {^[0-9a-fA-F]+[ ][0-9a-fA-F]+$} $ReturnValue]==0} {
- ChildAlertDialog .memoryViewer "There was a problem with one of the addresses entered!!!"
- return
- }
- scan "$ReturnValue" "%x %x" start end
- if {($start < 0) || ($end > $MemoryViewer(MaximumAddress)) || \
- ($start > $end)} {
- ChildAlertDialog .memoryViewer "There was a problem with one of the addresses entered!!!"
- return
- }
-
- set name [BtkFileSelector -in .memoryViewer \
- -text "Select file to append memory dump to:"]
- if {$name!=""} {
- if {[file isdirectory $name]} {
- ChildAlertDialog .memoryViewer {ERROR: The name specified is a directory!!!}
- return
- }
-
- ## Calculate the words per line for an 80 column text file
- set WPL [expr (80-1-$MemoryViewer(AddressLength))/\
- (1+$MemoryViewer(WordLength))]
-
- ## Get the length, address, and WPL in hexidecimal form
- set length [format "%x" [expr $end-$start+1]]
- set address [format "%x" $start]
- set wpl [format "%x" $WPL]
-
- ## Open the output file
- if {[catch {open $name "a+"} file] != 0} {
- ChildAlertDialog .memoryViewer "ERROR: Couldn't open $name for appending!!!"
- return
- }
-
- ## Ask simulator for memory dump
- PutLine "ListMemory $MemoryViewer(AddressSpace) $address $length $wpl"
-
- ## Output memory dump to file
- set address $start
- foreach i [GetList] {
- set line "[format %0$MemoryViewer(AddressLength)x $address]: $i"
- puts $file $line
- set address [expr $address+$WPL]
- }
- puts $file ""
-
- close $file
- }
- }
- }
-
- ###############################################################################
- # Close the memory viewer window
- ###############################################################################
- proc CloseMemoryViewer {} {
- catch {destroy .memoryViewer}
- }
-
- ###############################################################################
- # Create and display the memory viewer window
- ###############################################################################
- proc OpenMemoryViewer {} {
- global Program
- global MemoryViewer
-
- ## We start at memory location 0 and address space 0
- set MemoryViewer(Address) 0
- set MemoryViewer(AddressSpace) 0
-
- ## Destroy the window if it exists
- catch {destroy .memoryViewer}
-
- ## Create the top level window
- toplevel .memoryViewer
- wm title .memoryViewer "Memory Viewer"
- wm iconname .memoryViewer "Memory Viewer"
-
- ## Create the text widget to display memory dump in
- text .memoryViewer.text -relief raised -borderwidth 2 -cursor left_ptr
- .memoryViewer.text tag configure WordSelectTag -foreground White \
- -background Black
- bind .memoryViewer.text <Any-KeyPress> "NOP"
- bind .memoryViewer.text <Any-ButtonPress> "NOP"
- bind .memoryViewer.text <Any-Motion> "NOP"
- bind .memoryViewer.text <Button-1> "MemoryViewerAlterMemory %x %y"
-
- ## Create buttons
- button .memoryViewer.dump -text "Dump..." \
- -command DumpMemoryViewer
- button .memoryViewer.address -text "Address..." \
- -command ChangeMemoryViewerAddress
- button .memoryViewer.up -bitmap @$Program(BitmapDir)/Up.xbm \
- -command {set MemoryViewer(Address) [expr $MemoryViewer(Address) - \
- $MemoryViewer(WPL)]; CheckMemoryViewerAddress; RefreshMemoryViewer}
- button .memoryViewer.down -bitmap @$Program(BitmapDir)/Down.xbm \
- -command {set MemoryViewer(Address) [expr $MemoryViewer(Address) + \
- $MemoryViewer(WPL)]; CheckMemoryViewerAddress; RefreshMemoryViewer}
- button .memoryViewer.pageUp -bitmap @$Program(BitmapDir)/PageUp.xbm \
- -command {set MemoryViewer(Address) [expr $MemoryViewer(Address) - \
- $MemoryViewer(WPS)]; CheckMemoryViewerAddress; RefreshMemoryViewer}
- button .memoryViewer.pageDown -bitmap @$Program(BitmapDir)/PageDown.xbm \
- -command {set MemoryViewer(Address) [expr $MemoryViewer(Address) + \
- $MemoryViewer(WPS)]; CheckMemoryViewerAddress; RefreshMemoryViewer}
- button .memoryViewer.dismiss -text "Dismiss" \
- -command {CloseMemoryViewer}
-
- pack .memoryViewer.text -side top -padx 2 -pady 2
- pack .memoryViewer.dump -side left -padx 2 -pady 2 -fill both -expand 1
- pack .memoryViewer.address -side left -padx 2 -pady 2 -fill both -expand 1
- pack .memoryViewer.up -side left -padx 2 -pady 2 -fill both -expand 1
- pack .memoryViewer.down -side left -padx 2 -pady 2 -fill both -expand 1
- pack .memoryViewer.pageUp -side left -padx 2 -pady 2 -fill both -expand 1
- pack .memoryViewer.pageDown -side left -padx 2 -pady 2 -fill both -expand 1
- pack .memoryViewer.dismiss -side left -padx 2 -pady 2 -fill both -expand 1
-
- PutLine "ListMaximumAddress $MemoryViewer(AddressSpace)"
- set MemoryViewer(MaximumAddress) [lindex [GetList] 0]
- set MemoryViewer(AddressLength) [string length $MemoryViewer(MaximumAddress)]
- scan $MemoryViewer(MaximumAddress) "%x" MemoryViewer(MaximumAddress)
-
- PutLine "ListGranularity"
- set MemoryViewer(WordLength) [expr [lindex [GetList] 0]*2]
-
- ## Get the width and height of the text window
- if {[scan [.memoryViewer.text configure -width] \
- "-width width Width 80 %d" width] != "1"} {
- set width "55"
- }
- if {[scan [.memoryViewer.text configure -height] \
- "-height height Height 24 %d" height] != "1"} {
- set height "10"
- }
-
- ## Calculate the number of words per line
- set MemoryViewer(WPL) [expr ($width-1-$MemoryViewer(AddressLength))/(1+$MemoryViewer(WordLength))]
-
- ## Calculate the number of words per screen
- set MemoryViewer(WPS) [expr ($height*$MemoryViewer(WPL))]
-
- RefreshMemoryViewer
- }
-
-